<empty name="Think.get.buyUrl">

<!-- 收货地址的编辑 -->
<div id="deliver-address" class="deliver-address">
<volist name="deliverAddressLists" id="vo">
<section class="my mg10 transition">
  <div class="my-item my-address-item">
    <a class="link" href="__CONTROLLER__/modifyDeliverAddress/sid/{$sid}/id/{$vo.id}">
      <p><strong>{$vo.name}</strong>&nbsp;&nbsp;{$vo.tel}</p>
      <p>{$vo.provinceName} {$vo.cityName} {$vo.areaName} {$vo.address}</p>
      <a class="del btn btn-red transition" data-id="{$vo.id}">删除</a>
    </a>
  </div>
</section>
</volist>
<section class="my mg10">
  <div class="my-item">
    <a class="link" href="__CONTROLLER__/addDeliverAddress/sid/{$sid}">添加新地址</a>
  </div>
</section>
</div>
<script type="text/javascript">
  //删除地址功能能，左滑出现删除按钮，右滑消失，点击跳转。
  (function(){
    var addressItem = document.querySelectorAll ( "#deliver-address .my-address-item" ),
        delButtons = document.querySelectorAll ( "#deliver-address .del" );
    for ( var i=0; item=addressItem[i]; i++ ) {
      item.addEventListener ( "touchstart", bindTouchStart, false );
      item.addEventListener ( "touchmove", bindTouchMove, false );
      item.addEventListener ( "touchend", bindTouchEnd, false );
    };
    for ( var i=0; item=delButtons[i]; i++ ) {
      item.addEventListener ( "touchend", delAddress, false );
    };
    var startX = 0,
        startY = 0;
    function bindTouchStart ( e ) {
    	e.preventDefault();
      var touch = e.touches[0];
      startX = touch.pageX;
      startY = touch.pageY;
    };
    function bindTouchMove ( e ) {
    	e.preventDefault();
      var touch = e.touches[0];
      var x = touch.pageX - startX,
          y = touch.pageY - startY;
      if ( x < -30 && y < 70 ) {
        this.querySelector ( ".del" ).style.WebkitTransform = "translate(-10.5em, -50%)";
      } else if ( x > 30 && y < 70 ) {
    	  this.querySelector ( ".del" ).style.WebkitTransform = "translate(10.5em, -50%)";
      };
    };
    function bindTouchEnd ( e ) {
    	var touch = e.changedTouches[0];
      var x = touch.pageX - startX,
          y = touch.pageY - startY;
      if ( x == 0 & y == 0 ) {
    	  location.href = this.children[0].getAttribute ( "href" );
      }
    };
    function delAddress ( e ) {
      var id = this.getAttribute ( "data-id" ),
          sid = {$sid},
          _this = this;
      e.stopPropagation();
      modal.confirm ( "删除后无法恢复，确定要删除吗？", function(){
        GH.ajax ( "__CONTROLLER__/deleteDeliverAddress", {"id": id, "sid": sid}, function(data){
          GH.showMessage ( data.msg );
          if ( data.error == 0 ) {
            _this.parentNode.parentNode.style.height = "0";
            setTimeout( function(){
              _this.parentNode.parentNode.remove();
            }, 1000 );
          }
        }, "post" );
      });
    };
  })();
</script>

<else/>

<!-- 收货地址的选择 -->
<div id="deliver-address" class="deliver-address pd10">
  <a class="btn btn-brown db w100 mb10" href="__CONTROLLER__/addDeliverAddress/sid/{$sid}?buyUrl={$buyUrl}">新增收货地址</a>
  <volist name="deliverAddressLists" id="vo">
  <section class="address-item pd10 mb10{$vo['status']?' active':''}" data-address-id="{$vo.id}">
    <p><strong>{$vo.name}</strong>&nbsp;&nbsp;{$vo.tel}</p>
    <p>{$vo.provinceName} {$vo.cityName} {$vo.areaName} {$vo.address}</p>
  </section>
  </volist>
</div>
<script type="text/javascript">
  (function(){
   var oAddress = document.getElementById ( "deliver-address" ),
       buyUrl = "{$_GET['buyUrl']}";
   GH.delegate( "click", oAddress, "section", function(){
    var deliverId = this.getAttribute ( "data-address-id" ),
        sid = {$sid};
    GH.ajax ( "__CONTROLLER__/updateAddressStatus", { "deliverId": deliverId, sid: sid }, function(data){
     ( data.error == 0 ) && ( window.location = buyUrl );
    }, "post" );
   });
  })()
</script>

</empty>

